# coding:UTF-8
"""字符串学习"""


def add_prefix_un(word):
    """
    添加前缀un
    :param word: str of a root word
    :return:  str of root word with un prefix

    This function takes `word` as a parameter and
    returns a new word with an 'un' prefix.
    """
    return "un" + word


def make_word_groups(vocab_words):
    """

    :param vocab_words: list of vocabulary words with a prefix.
    :return: str of prefix followed by vocabulary words with
             prefix applied, separated by ' :: '.

    This function takes a `vocab_words` list and returns a string
    with the prefix  and the words with prefix applied, separated
     by ' :: '.
    """
    if len(vocab_words) < 1:
        return ""
    return vocab_words[0] + " :: " + " :: ".join([vocab_words[0]+f for f in vocab_words[1:]])


def remove_suffix_ness(word: str):
    """
    还原ness后缀的单词
    :param word: string  str of word to remove suffix from.
    :return: str of word with suffix removed & spelling adjusted.

    This function takes in a word and returns the base word with `ness` removed.
    """
    suffix = 'ness'
    if word.endswith(suffix):
        tmp_word = word.replace(suffix, '', 1)
        if tmp_word.rfind('i') == len(tmp_word) - 1:
            return tmp_word[0:-1] + 'y'
        return tmp_word
    return word


def noun_to_verb(sentence: str, index: int):
    """

    :param sentence: str that uses the word in sentence
    :param index:  index of the word to remove and transform
    :return:  str word that changes the extracted adjective to a verb.

    A function takes a `sentence` using the
    vocabulary word, and the `index` of the word once that sentence
    is split apart.  The function should return the extracted
    adjective as a verb.
    """
    try:
        return sentence.replace(".", "").split(" ")[index] + "en"
    except ValueError:
        return ""
